package cn.faifai.desktop.view;

import cn.faifai.desktop.view.components.treeDirectory.DirectoryBrowser;
import cn.faifai.desktop.view.components.treeDirectory.FileBrowser;
import cn.faifai.desktop.view.components.FileDetail;
import cn.faifai.desktop.view.components.HeaderBar;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

// 主页面组装
@Component
public class MainView {
    private BorderPane root;

    @Autowired
    FileBrowser fileBrowser;
    @Autowired
    FileDetail fileDetail;
    @Autowired
    DirectoryBrowser directoryBrowser;

    public MainView init(BorderPane root) {
        this.root = root;

        // 组合头部
        HeaderBar header = new HeaderBar("文件标签管理系统");
        root.setTop(header.getView());

        // 侧边组件
        // 创建可拖拽的分隔容器
        SplitPane resizeContainer = new SplitPane();
//        resizeContainer.getItems().addAll(fileBrowser.initUI(), fileDetail.initUI());
        resizeContainer.getItems().addAll(directoryBrowser.initUI(), fileDetail.initUI());

        // 关键配置参数
        resizeContainer.setDividerPosition(0, 0.2); // 初始宽度占20%
        resizeContainer.getDividers().get(0).setPosition(0.2); // 同步初始化位置

        // 替换原有设置语句
        root.setCenter(resizeContainer);
        return this;
    }

//    public static MainView getInstance() { return instance; }

    public BorderPane getRoot() { return root; }
}